inputFileName1 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_phase0.txt.input"
inputFileHandler1 = open(inputFileName1,"r")

inputFileName2 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_output_feature_new_phase1.txt"
inputFileHandler2 = open(inputFileName2,"r")

outputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3_output_feature_new_phase0_1.txt"
outputFileHandler = open(outputFileName,"w")


file1Lines = inputFileHandler1.readlines()

for index,line in enumerate(inputFileHandler2.readlines()):
    elementsFromFile2 = line.strip().split(" ")
    queryIDFromFile2 = elementsFromFile2[0]
    trecIDFromFile2 = elementsFromFile2[1]
    
    elementsFromFile1 = file1Lines[index].strip().split(" ")
    queryIDFromFile1 = elementsFromFile1[0]
    trecIDFromFile1 = elementsFromFile1[1]
    
    outputLine = ""    
    outputLine += elementsFromFile1[0] + " " + elementsFromFile1[1] + " " + elementsFromFile1[2] + " " + elementsFromFile1[3] + " " + elementsFromFile1[-8] + " " + elementsFromFile1[-7] + " " + elementsFromFile1[-6] + " " + elementsFromFile1[-5] + " " + elementsFromFile1[-4] + " " + elementsFromFile1[-3] + " " + elementsFromFile1[-2] + " "
    
    for index,element in enumerate(elementsFromFile2):
        if index != 0 and index != 1:
            outputLine += elementsFromFile2[index] + " "
            
    outputLine += elementsFromFile1[-1]
    
    outputFileHandler.write(outputLine.strip() + "\n")
    

outputFileHandler.close() 
    
'''
# checking
print "index:",index

if queryIDFromFile1 == queryIDFromFile2 and trecIDFromFile1 == trecIDFromFile2:
    pass
else:
    print "error","queryIDFromFile1:",queryIDFromFile1,"queryIDFromFile2:",queryIDFromFile2,"trecIDFromFile1:",trecIDFromFile1,"trecIDFromFile2:",trecIDFromFile2
    exit(1)
'''





'''
import os
basePath = "/data4/team/weijiang/human_judge_web_pages_plain_text_only_words_beautiful/"
for i in range(0,134):
    dirName = "en%04d" % i
    newPath = basePath + dirName
    print newPath
    os.mkdir(newPath)
'''

'''
inputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input"
inputFileHandler = open(inputFileName,"r")

outputFileName1 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part1"
outputFileHandler1 = open(outputFileName1,"w")

outputFileName2 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part2"
outputFileHandler2 = open(outputFileName2,"w")

outputFileName3 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part3"
outputFileHandler3 = open(outputFileName3,"w")

outputFileName4 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part4"
outputFileHandler4 = open(outputFileName4,"w")

outputFileName5 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part5"
outputFileHandler5 = open(outputFileName5,"w")

outputFileName6 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part6"
outputFileHandler6 = open(outputFileName6,"w")

outputFileName7 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part7"
outputFileHandler7 = open(outputFileName7,"w")

outputFileName8 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part8"
outputFileHandler8 = open(outputFileName8,"w")

outputFileName9 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part9"
outputFileHandler9 = open(outputFileName9,"w")

outputFileName10 = "/data5/team/weijiang/the_new_trip_of_feature_generation/wholeTrainingFileTempleteV3.txt.input.part10"
outputFileHandler10 = open(outputFileName10,"w")


for line in inputFileHandler.readlines():
    queryID = int(line.strip().split(" ")[0])
    if queryID >= 1 and queryID <=15:
        outputFileHandler1.write(line)
    if queryID >= 16 and queryID <=30:
        outputFileHandler2.write(line)
    if queryID >= 31 and queryID <=45:
        outputFileHandler3.write(line)   
    if queryID >= 46 and queryID <=60:
        outputFileHandler4.write(line)
    if queryID >= 61 and queryID <=75:
        outputFileHandler5.write(line)
    if queryID >= 76 and queryID <=90:
        outputFileHandler6.write(line)
    if queryID >= 91 and queryID <=105:
        outputFileHandler7.write(line)
    if queryID >= 106 and queryID <=120:
        outputFileHandler8.write(line)
    if queryID >= 121 and queryID <=135:
        outputFileHandler9.write(line)
    if queryID >= 136 and queryID <=150:
        outputFileHandler10.write(line)
'''   
#print directory
#os.mkdir(directory)
